<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" href="/css/font.css">
		<link rel="stylesheet" href="/css/xadmin.css">
		<style>
			form {
				margin-top: 20px;
			}
			input {
				width: 80% !important;
			}
			
		</style>
	</head>
	<body>
		<form class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label">新密码</label>
				<div class="layui-input-block">
					<input type="password" name="password" lay-verify="required|password" placeholder="密码必须6到12位，且不能出现空格" autocomplete="off" class="layui-input">
					<input type="hidden" name="id" th:attr="value=${ sysUserId }">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认密码</label>
				<div class="layui-input-block">
					<input type="password" name="confirmPas" lay-verify="required|confirmPas" placeholder="密码必须6到12位，且不能出现空格" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="update" type="button">立即提交</button>
				</div>
			</div>
		</form>
		
	<script type="text/javascript" src="/js/jquery.min.js"></script>
	<script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="/js/xadmin.js"></script>
	<script>
		layui.use(['form', 'layedit', 'laydate'], function(){
			var form = layui.form
			,layer = layui.layer
			
			//自定义验证规则
			form.verify({
				password: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格'],
				confirmPas: function(value) {
					var password = $('input[name=password]').val();
					if(value != password) {
						return "两次输入密码不一致";
					}
				}
			});
		
			//监听提交
			form.on('submit(update)', function(data){
				$.ajax({
                    url : "/sys/sysUser/updatePassword",
                    type : "post",
                    data : {
                        id: data.field.id,
                        password: data.field.password
                    },
                    success : function(result) {
                        if (result.state) {
                            layer.msg('修改成功！', {icon: 1}, function(){
								// 1.先得到当前iframe层的索引
								var index = parent.layer.getFrameIndex(window.name); 
								// 2.再执行关闭 
								parent.layer.close(index); 
                            });
                        } else {
                            layer.msg(""+result.msg, {icon: 5});
                        }
                    }
                });
			});
		});
	</script>
	</body>
</html>
